//渲染页面的插件
import fs from 'fs'
import path from 'path'
import nunjucks from 'nunjucks'

export let Rander = function(){
    return async (ctx,next) => {
        ctx.rander = function(html,obj,views='views'){
            let filePath = fs.readdirSync(views).filter(item => item.endsWith(`${html}.html`)).map(item =>path.resolve('.')+ '/' + path.join(views, item))
            let env = nunjucks.configure()
            ctx.body = env.render(filePath[0],obj)
        }
        await next()
    }
}